#include <iostream>
#include <cmath>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;

// jiri blazek 3th 397
// 为什么用clang 就直接不能运行呢？
int main()
{
    constexpr int max_dim = 10000;
    const double pi = 4 * atan(1.0);

    string grid_file;
    double in_area{0.0}, out_area{0.0};
    int ncell{0}, ncthroat{0};
    // 读入文件数据
    string infname = "input.dat";
    ifstream input{infname, ios_base::in};
    if(!input) { cerr << "cannot open input.dat" << "\n";}
    input >> grid_file >> in_area >>
        out_area >> ncell >> ncthroat;
    cout << grid_file << "\n"
         << in_area << "\n"
         << out_area << "\n"
         << ncell << "\n"
         << ncthroat << "\n";

    input.close();

    // 设置参数
    int ib2{ncell + 2}, imax{ncell + 3};
    double dx{1.0 / ncell}, xthroat{dx * ncthroat};
    double x[max_dim], area[max_dim];
    x[0] = x[1] = 0.0;
    for (int i = 2; i < ib2; ++i)
    {
        x[i] = x[i - 1] + dx;
    }
    x[ib2 - 1] = x[imax - 1] = 1.0;

    // 计算面积
    area[0] = area[1] = in_area;
    for (int i = 2; i < ib2; ++i)
    {
        if (x[i] <= xthroat)
            area[i] = 1.0 + 0.5 * (in_area - 1.0) * (1.0 + cos(pi * x[i] / xthroat));
        else
            area[i] = 1.0 + 0.5 * (out_area - 1.0) * (1.0 - cos(pi * (x[i] - xthroat) / (1.0 - xthroat)));
    }
    area[ib2-1] = area[imax-1] = out_area;

    // 输出到文件
    ofstream output{grid_file, ios_base::out};
    if(!output) { cerr << "cannot open " << grid_file << "\n";}

    output << imax << "\n";
    output << setprecision(7) << scientific;
    for(int i = 0; i < imax; ++i)
    {
        output << x[i] << "\t" << area[i] << "\n";
    }
    output.close();

    return 0;
}